//
//  BVSearchBar.m
//  BuyVegetable
//
//  Created by yushanchang on 16/9/30.
//  Copyright © 2016年 com.yinding. All rights reserved.
//

#import "BVSearchBar.h"
#import "UIImage+BVImage.h"
#import "UIView+Extension.h"

@interface BVSearchBar ()<UITextInput>

@end

@implementation BVSearchBar

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = COLOR_RGB(253, 120, 67);
        self.font = [UIFont systemFontOfSize:15];

        NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
        attrs[NSFontAttributeName] = [UIFont systemFontOfSize:15];
        attrs[NSForegroundColorAttributeName] = [UIColor BVBackgroundLightGrayColor];
        NSAttributedString *attr = [[NSAttributedString alloc] initWithString:@"请输入商品关键字" attributes:attrs];
        self.attributedPlaceholder = attr;
        
        UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"soushuo"]];
        imageV.width = 17;
        imageV.height = 17;
        self.leftView = imageV;
        self.leftViewMode = UITextFieldViewModeAlways;
    }
    return self;
}

#pragma mark - 
#pragma mark - UITextInput
- (CGRect)leftViewRectForBounds:(CGRect)bounds{
    return CGRectMake(10, 8, 17, 17);
}
- (CGRect)editingRectForBounds:(CGRect)bounds{
    return CGRectMake(33, 0.3, 150, 36);
}
- (CGRect)placeholderRectForBounds:(CGRect)bounds{
    return CGRectMake(33, 0.3, 150, 36);
}
- (CGRect)caretRectForPosition:(UITextPosition *)position{
    CGRect originalRect = [super caretRectForPosition:position];
    originalRect.size.height = self.font.lineHeight;
    return originalRect;
}

@end
